#encoding=utf-8

import zmq
import time

def zeromqServer():  #建服务器
    context = zmq.Context()   
    socket = context.socket(zmq.REP)   
    socket.bind("tcp://127.0.0.1:5000")
    return socket

def sendMsg(socket,msg):#发消息
    time.sleep(3)
    socket.send(msg)

def receiveMsg(socket):#收消息
    msg = socket.recv()
    return msg

def processMsg(msg):#处理消息
    a,b = [int(x) for x in msg.split('\t')]
    print a,b
    msg = str(a+b)
    return msg

if __name__=="__main__":
    socket = zeromqServer()
    print 'Server is running....'
    while True:
        msg = socket.recv()
        msg = processMsg(msg)
        socket.send(msg)